package cn.qy.java.base.ch21;

public class Ch21_08_ThreadLocalDemo {
	
	static ThreadLocal<String> tl = new ThreadLocal<>();
	// InheritableThreadLocal 让子线程可以访问在父线程中设置的本地变量
	static ThreadLocal<String> tl2 = new InheritableThreadLocal<>();

	
	public static void main(String[] args) throws InterruptedException {
		tl.set("zhangsan");
		new Thread() {
			public void run() {
				System.out.println("before remove " + tl.get());
				tl.remove();
				System.out.println("after remove " + tl.get());
			}
		}.start();
		Thread.sleep(500);
		System.out.println(tl.get());

		
		tl2.set("lisi");
		new Thread() {
			public void run() {
				System.out.println("before remove " + tl2.get());
				tl2.remove();
				System.out.println("after remove " + tl2.get());
			}
		}.start();
		Thread.sleep(500);
		System.out.println(tl2.get());

	}

}
